package com.end;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.*;

public class Exam3 {
    public static void main(String[] args) throws Exception {
        BufferedReader bufferedReader = new BufferedReader(new FileReader("./src/com/end/系统菜单.txt"));
        List<String> list = new ArrayList<>();
        String temp = null;
        while(true){
            temp = bufferedReader.readLine();
            if(temp == null)break;
            list.add(temp);
        }
        Collections.sort(list, new Comparator<String>(){

            @Override
            public int compare(String o1, String o2) {
                if(o1.length() < o2.length()){
                    return -1;
                }else if(o1.length() > o2.length()){
                    return 1;
                }else{
                    return 0;
                }
            }
        });
        System.out.println(list);
        Map<String, List<String>> map = new HashMap<>();
        for(String temp2 : list){
            String[] spiltString = temp2.split("-");
            if(spiltString[0].length() == 4){
                List<String> list1 = new ArrayList<>();
                map.put(temp2, list1);
            }else{
                for(String temp3 : map.keySet()){
                    if(temp3.substring(0, 4).equals(spiltString[0].substring(0, 4))){
                        map.get(temp3).add(temp2);
                    }
                }
            }
        }
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("./src/com/end/系统菜单2.txt"));
        for(String temp2 : map.keySet()){
            bufferedWriter.write(temp2 + "\n");
            for(String temp3 : map.get(temp2)){
                bufferedWriter.write("\t" + temp3 + "\n");
            }
            bufferedWriter.flush();
        }

    }
}
